<?php
/*
 * input params: unix timestamp, use strtotime 
 * */

class QDateTime
{
	private function QDateTime(){}

    public static function getInstance()
    {
        static $ins;
        if (false == $ins instanceof QDateTime)
        {
            $ins = new QDateTime();
        }
        return $ins;
    }
		
	public static function dayDiff($fromTime, $toTime)
	{
		return self::convertResult(($fromTime - $toTime) / 86400 );
	}
	
	public static function hourDiff($fromTime, $toTime)
	{
		return self::convertResult(($fromTime - $toTime) / 3600 );
	}
	
	public static function minuteDiff($fromTime, $toTime)
	{
		return self::convertResult(($fromTime - $toTime) / 60 );
	}
	
	public static function secondDiff($fromTime, $toTime)
	{
		return self::convertResult($fromTime - $toTime);
	}
	
	public static function dayDiffFromNow($time)
	{
		return self::convertResult((time() - $time) / 86400);
	}
	
	public static function hourDiffFromNow($time)
	{
		return self::convertResult((time() - $time) / 3600);
	}
	
	public static function minuteDiffFromNow($time)
	{
		return self::convertResult((time() - $time) / 60);
	}
	
	public static function secondDiffFromNow($time)
	{
		return self::convertResult(time() - $time);
	}
	
	private static function convertResult($result)
	{
		if($result < 0)
		{
			$result = (-1) * $result;
		}
		return $result;
	}
		
	public static function getDateNow($format = '%Y%m%d')
    {
        return strftime($format, time());
    }
	public static function getYearNow()
	{
		return self::getDateNow("%Y");
	}
	
	public static function getMonthNow()
	{
		return self::getDateNow("%m");
	}
	
	public static function getDayNow()
	{
		return self::getDateNow("%d");
	}
}
